#pragma once
template<class T>
struct Less
{
	bool operator()(const T& x, const T& y)
	{
		return x < y;
	}
};

template<class T>
struct Greater
{
	bool operator()(const T& x, const T& y)
	{
		return x > y;
	}
};


template<class T, class Con = vector<T>,class Com = Less<T>>
class priority_queue
{
	void adjust_up(size_t child)
	{
		
		size_t parent = (child - 1) / 2;
		while (child > 0)
		{
			//if (_c[child] > _c[parent])
			if(com(  _c[parent],_c[child]))
			{
				swap(_c[child], _c[parent]);
				child = parent;
				parent = (child - 1) / 2;
			}
			else
			{
				break;
			}
		}
	}
	void adjust_down(size_t parent)
	{
		Com com;
		size_t child = (parent * 2) + 1;
		while (child < _c.size()) 
		{
			if (child + 1 < _c.size() && /*_c[child] < _c[child + 1]*/ com(_c[child] , _c[child+1]))
				child++;
			//if (_c[child] > _c[parent]) 
			if(com( _c[parent],_c[child] ))
			{
				swap(_c[child], _c[parent]);
				parent = child;
				child = (parent * 2) + 1;
			}
			else
			{
				break;
			}
		}
	}
public:
	priority_queue()
	{
		Con _c;
	}

	void push(const T& x)
	{
		_c.push_back(x);
		adjust_up(_c.size()-1);
	}

	void pop()
	{
		swap(_c[0], _c[_c.size() - 1]);
		_c.pop_back();
		adjust_down(0);
	}

	bool empty()
	{
		return _c.empty();
	}
	
	size_t size()
	{
		return _c.size();
	}

	const T& top()
	{
		return _c[0];
	}

private:
	Con _c;
	Com com;
};

